
/**
 * Copyright 2009 cestum.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package org.waveprotocol.wave.model.document.operation.automaton {
import org.waveprotocol.wave.model.util.Preconditions;

/**
 * The overall result of validating an operation.
 *
 */
public class ValidationResult {
	
	  /**
	   * The name of this enum constant.
	   */
	   var name:String;

	  /**
	   * The number of this enum constant.  Each constant is given a number
	   * which matches the order in which it was declared, starting with zero.
	   */
	 var ordinal:int;
     static var values:Array = new Array();
	
	public static var ILL_FORMED:ValidationResult= new ValidationResult(0, "ILL_FORMED");
	public static var INVALID_DOCUMENT:ValidationResult= new ValidationResult(1, "INVALID_DOCUMENT");;
	public static var INVALID_SCHEMA:ValidationResult= new ValidationResult(2, "INVALID_SCHEMA"); ;
	public static var VALID:ValidationResult= new ValidationResult(3, "VALID");;
	
	public function ValidationResult(i:int, string:String) {
		this.ordinal = i;
		this.name = string;
		values[i] = this;
	}
	
	public function getOrdinal():int {
		return this.ordinal;
	}
	
	//public static ValidationResult[] values() {
	public static function getValues():Array {
		return  values;
	}

	//START OF ENUMs//
	
	/** @see #ILL_FORMED */
    public function isIllFormed():Boolean {
      return this == ILL_FORMED;
    }
    /** @see #INVALID_DOCUMENT */
    public function isInvalidDocument():Boolean {
      return this == INVALID_DOCUMENT;
    }
    /** @see #INVALID_SCHEMA */
    public function isInvalidSchema():Boolean {
      return this == INVALID_SCHEMA;
    }
    /** @see #VALID */
    public function isValid():Boolean {
      return this == VALID;
    }

    public function mergeWith(other:ValidationResult):ValidationResult {
      Preconditions.checkNotNull(other, "Null ValidationResult");
      return ValidationResult.getValues()[Math.min(this.getOrdinal(), other.getOrdinal())];
    }

}
}